package com.events.testservice.dao;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.events.testservice.entity.SalesOrderEntity;
import com.events.testservice.repository.SalesOrderRepository;

/**
 * Data Access Object for sales order.
 * @author Ashish Sonawane
 *
 */
@Component
public class SalesOrderDao {

	@Autowired
    private SalesOrderRepository salesOrderRepository;
	
	/**
	 * Find sales order by id.
	 * @param id
	 * @return
	 */
	public SalesOrderEntity findSalesOrderById(Long id) {
        return salesOrderRepository.findOne(id);
    }
	
	/**
	 * create new sales order.
	 * @param entity
	 * @return
	 */
	public SalesOrderEntity createSalesOrder(SalesOrderEntity entity) {
        return salesOrderRepository.save(entity);
    }
	
	/**
	 * delete sales order by id.
	 * @param id
	 */
	public void deleteSalesOrderById(Long id) {
        salesOrderRepository.delete(id);
    }
	
	/**
	 * update sales order name by id.
	 * @param id
	 * @param orderNameNew
	 * @return
	 */
	public SalesOrderEntity updateOrderById(Long id , String orderNameNew){
		SalesOrderEntity entity = salesOrderRepository.findOne(id);
		entity.setOrdername(orderNameNew);
		salesOrderRepository.save(entity);
		return entity;
	}
}
